from data.bbox.bbox_dataset import DetectionDataset
import json,os
from pprint import pprint
import pandas as pd
import numpy as np
class ResultDataset(DetectionDataset):
    def __init__(self):
        super(ResultDataset,self).__init__()
        anno = json.load(open("/home/zyx/Downloads/res_combine_kohill1 (1).json","rt"))["results"]
        map_csv = "/data1/zyx/yks/dataset/retail/map_test1.csv"
        id2name = open(map_csv,"rt").readlines()[1:]
        id2name = {l.strip().split(',')[1]:l.strip().split(',')[0] for l in id2name}
        self.id2name = id2name
        self.objs = anno
        self.classes = ["male","female"]
    def __len__(self):
        return len(self.objs)
    def at_with_image_path(self, idx):
        bboxes = []
        obj = self.objs[idx]["object"]
        image_id = self.objs[idx]["image_id"]
        for bbox in obj:
            xmin = bbox["minx"]
            ymin = bbox["miny"]
            xmax = bbox["maxx"]
            ymax = bbox["maxy"]
            male = bbox["male"]
            female = bbox["female"]
            if male > .5:
                bboxes.append([xmin,ymin,xmax,ymax,0])
            if female > .5:
                bboxes.append([xmin,ymin,xmax,ymax,1])
        filename = self.id2name[image_id]
        path = os.path.join("/data1/zyx/yks/dataset/retail/test_images/test", filename)
        return path, np.array(bboxes)
ResultDataset().viz()